/*
ID: icerupt1
PROG: charrec
LANG: C++11
*/

/* solution
 *
 * 
*/
#include <fstream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <string>

FILE *font_in  = fopen ("font.in", "r");
FILE *fin  = fopen ("charrec.in", "r");
FILE *fout = fopen ("charrec.out", "w");

int const maxn = 1207;
int const maxc = 64;
int const font_c = 27;
int f[maxn][maxc];
char g[maxn][maxn];
int path[maxn][maxn];
int n;

std::vector<std::vector<std::string>> font;
std::vector<std::string> da;

void init()
{
	fscanf(font_in, "%d", &n);
	font.resize(font_c);
	for (int i = 0; i < font_c; i++) {
		font[i].resize(20);
		for (int j = 0; j < 20; j++) {
			char tmp[21];
			fscanf(font_in, "%s", tmp);
			font[i][j] = tmp;
		}
	}
}

int string_same(std::string s1, std::string s2)
{
	int tmp = 0;
	for (int i = 0; i < (int)s1.size(); i++) {
		if (s1[i] == s2[i]) tmp++; }
	return tmp;
}

int compare(int start, int len, char & ch)
{
	int same = 0;
	for (int c/*haracter*/ = 0; c < 27; c++) {
		if (len == 20) {
			int tmp = 0;
			for (int i = 4; i < 17; i++)
				tmp += string_same(font[c][i], da[start + i]);
			if (tmp > same) {
				same = tmp;
				ch = ((c == 0) ? ' ' : char('a' + c - 1));
			}
		//	std::cout << char('a' + c - 1) << ' ' << tmp << '\n';
		} else
		if (len == 21) {
			for (int i = 0; i < 20; i++) {
				int tmp = 0;
				for (int j = 4; j < 17; j++) {
					if (j < i) tmp += string_same(font[c][j], da[start + j]);
					else
					if (j >= i) tmp += string_same(font[c][j], da[start + j + 1]);
				}
				if (tmp > same) {
					same = tmp;
					ch = ((c == 0) ? ' ' : char('a' + c - 1));
				}
			}
		} else
		if (len == 19) {
			for (int i = 0; i < 20; i++) {
				int tmp = 0;
				for (int j = 4; j < 17; j++) {
					if (j < i) tmp += string_same(font[c][j], da[start + j]);
					else
					if (j > i) tmp += string_same(font[c][j], da[start + j - 1]);
				}
				if (tmp > same) {
					same = tmp;
					ch = ((c == 0) ? ' ' : char('a' + c - 1));
				}
			}
		}

	}
	return same;
}

int dfs(int i, int j)
{
	if (f[i][j]) return f[i][j];
	if (i < 19) return 0;
	if (j == 0) return 0;
	char ch1 = '!', ch2 = '!', ch3 = '!';
	int t1 = 0, t2 = 0, t3 = 0;
	t1 = dfs(i-19, j-1) + compare(i-19, 19, ch1);
	if (i >= 20) t2 = dfs(i-20, j-1) + compare(i-20, 20, ch2);
	if (i >= 21) t3 = dfs(i-21, j-1) + compare(i-21, 21, ch3);

	if (t1 > f[i][j]) {
		f[i][j] = t1; g[i][j] = ch1; path[i][j] = i-19;
	}
	if (t2 > f[i][j]) {
		f[i][j] = t2; g[i][j] = ch2; path[i][j] = i-20;
	}
	if (t3 > f[i][j]) {
		f[i][j] = t3; g[i][j] = ch3; path[i][j] = i-21;
	}

	return f[i][j];
}

int main()
{
	init();

	fscanf(fin, "%d", &n); da.resize(n);
	for (int i = 0; i < n; i++) {
		char tmp[21];
		fscanf(fin, "%s", tmp);
		da[i] = tmp;
	}

	int tot = int(n/21), max = 0;
	for (int i = tot; i <= int(n/19); i++)
		if (dfs(n, i) > max) { tot = i; max = f[n][i]; }

	std::string ans;
	for (int pos = n; tot; tot--) {
		ans += g[pos][tot];
		pos = path[pos][tot];
	}
	std::reverse(ans.begin(), ans.end());
	printf("%s\n", ans.c_str());
	fprintf(fout, "%s\n", ans.c_str());
}

